# apps/monitoring/utils.py
from apps.monitoring.models import ActionLog

def log_action(*, action_type: str, user=None, device=None,
               old_value=None, new_value=None):
    """
    统一写 ActionLog，任何地方 import 后直接调用。
    """
    ActionLog.objects.create(
        user=user, device=device,
        action_type=action_type,
        old_value=str(old_value) if old_value is not None else None,
        new_value=str(new_value) if new_value is not None else None
    )